<template>
  <div class="container">
    <div class="seat-box">
      <!-- <div class="dashedLine" /> -->
      <div class="seat">
        <div v-for="trIndex in trNumArr" :key="trIndex" class="item_row">
          <div v-for="tdIndex in tdNumArr" :key="tdIndex" class="item_col">
            <div @click="selectype(getSeatNumber(tdIndex, trIndex))">
              <!-- {{seatInfo[getSeatNumber(tdIndex, trIndex)].seatType}} -->
              <div v-if="seatInfo[getSeatNumber(tdIndex, trIndex)].seatType == '1'">
                <div class="cansee" />
              </div>
              <div v-if="seatInfo[getSeatNumber(tdIndex, trIndex)].seatType == '2'">
                <div class="repair">
                  <img src="../../assets/icon/wxicon.png" alt="">
                  <div>修理中</div>
                </div>
              </div>
              <div v-if="seatInfo[getSeatNumber(tdIndex, trIndex)].seatType == '3'">
                <div class="hidden" />
              </div>
            </div>
          </div>
        </div>
        <div class="teacher">教师讲台</div>
      </div>
      <el-dialog title="位置状态" :visible.sync="showtype">
        <el-form>
          <el-form-item label="修改当前位置状态:">
            <el-radio-group v-model="nowtpye">
              <el-radio label="1">显示</el-radio>
              <el-radio label="3">隐藏</el-radio>
              <el-radio label="2">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="showtype = false">取 消</el-button>
          <el-button type="primary" @click="suretype">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { courseTimetablePage } from '@/api/course'
import { schoolClassroomseatSeatInfo, classSeatStatusUpdate } from '@/api/class'

import { getFileUrl, listQueryFilter } from '@/utils/tool'

export default {
  name: 'SeatMoban',
  data() {
    return {
      nowtpye: '',
      showtype: false,
      nowsetseat: '', // 当前正在操作的座位
      canpelist: [],
      drawer: false,
      direction: 'ltr',
      timetableInfoList: null,
      list: null,
      seatInfo: [],
      tdNumArr: [],
      trNumArr: [],
      tdNum: 0, // 一行显示多少个组
      trNum: 0,
      isActive: 0,
      noShowArr: [],
      noUseArr: [],
      temp: [{
        id: '',
        name: '',
        x_num: '',
        y_num: '',
        no_show: '',
        no_use: '',
        sort: ''
      }],
      listQuery: {
        id: this.$route.query.id
      },
      timetableListQuery: {
        page: 1,
        limit: 1,
        id: this.$route.query.id
      },
      canpeQuery: {
        page: 1,
        limit: 9999,
        course_timetable_id: this.$route.query.id,
        seat: 0
      }

    }
  },
  created() {
    // this.getTimetableInfo()
    this.getList()
  },
  methods: {
    getTimetableInfo() {
      this.timetableListQuery = listQueryFilter(this.timetableListQuery)
      courseTimetablePage(this.timetableListQuery).then(response => {
        this.timetableInfoList = response.data
        this.listQuery.id = this.timetableInfoList.class_room_seat_id
      })
    },
    getList() {
      this.listQuery = listQueryFilter(this.listQuery)
      schoolClassroomseatSeatInfo(this.listQuery).then(response => {
        this.tdNum = response.data.classRoomSeat.x_num
        this.trNum = response.data.classRoomSeat.y_num
        this.seatInfo = response.data.seatInfo
        for (var i = 1; i <= response.data.classRoomSeat.x_num; i++) {
          this.tdNumArr.push(i)
        }
        for (var j = 1; j <= response.data.classRoomSeat.y_num; j++) {
          this.trNumArr.push(j)
        }
      })
    },
    // 计算座位号
    getSeatNumber(indexX, indexY) {
      if (this.trNum % 2 === 1) {
        // 如果行数是单数，则最上面一行是递增
        if (indexY % 2 === 1) { // 代表是单数行还是偶数行
          // 如果是单数行则递增，偶数行则递减
          return this.tdNum * (this.trNum - indexY) + indexX
        } else {
          return this.tdNum * (this.trNum - indexY + 1) - indexX + 1
        }
      } else {
        // 如果行数是偶数，则最上面一行是递减
        if (indexY % 2 === 1) { // 代表是单数行还是偶数行
          // 如果是单数行则递增，偶数行则递减
          return this.tdNum * (this.trNum - indexY + 1) - indexX + 1
        } else {
          return this.tdNum * (this.trNum - indexY) + indexX
        }
      }
    },
    returnImageUrl(url) {
      return getFileUrl(url)
    },
    // 点击座位改变状态
    selectype(item) {
      this.nowsetseat = item
      this.showtype = true
    },
    // 点击确定修改位置状态
    suretype() {
      this.showtype = false
      var useraddQuery = {
        id: this.$route.query.id,
        num: this.nowsetseat,
        type: this.nowtpye
      }
      classSeatStatusUpdate(useraddQuery).then(response => {
        this.listQuery = listQueryFilter(this.listQuery)
        schoolClassroomseatSeatInfo(this.listQuery).then(response => {
          this.seatInfo = response.data.seatInfo
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .container{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    user-select: none;
    position: relative;
    .button{
      margin-top: 5px;
      position: absolute;
      right:10px;
      top:10px;
    }
    .teacher{
      height: 30px;
      width: 100px;
      background-color: #e3e3e3;
      border-radius: 4px;
      color: #585858;
      line-height: 30px;
      text-align: center;
      margin: 20px auto;
    }
    .seat-box{
      overflow: auto;
      width: 100%;
      position: relative;
      .dashedLine{
        width: 1%;
        height: 100%;
        position: absolute;
        left: 49%;
        top: 0;
        z-index: -1;
        border-right: 1px dashed #ccc8c8;
      }
      .seat{
        margin: 60px auto;
        // display: flex;
        flex-direction: column;
        // flex-direction: column-reverse;
        .item_row{
          // display: flex;
          white-space: nowrap;
        }
        .item_col{
          display: inline-block;
          vertical-align: top;
            cursor: pointer;
          width: 50px;
          height: 90px;
          margin: 5px 5px;
          .cansee{
            height: 90px;
            padding-top: 2px;
            box-shadow: -1px 1px 6px #ccc;
            text-align: center;
          }
          .hidden{
            height: 90px;
            background-color: #fafafa;
          }
          .repair{
            height: 90px;
            border: 1px dotted #ccc;
            text-align: center;
            font-size: 12px;
            color: #333;
            img{
              width: 60%;
              margin-top: 20px;
            }

          }
        }
      }
    }
    .canch{
      width: 90%;
      margin: 10px auto;
      height: 90%;
      background-color: #eee;
      overflow-y: scroll;
      padding: 10px;
      .item{
        display: block;
        width: 90%;
        margin: 5px auto 0px;
        cursor: pointer;

      }
    }
  }
</style>
